using System;
using System.Collections.Generic;
using System.Text;
using ESBSimpleSamples.ServiceClient.Generator.WSDL;
using System.IO;

namespace ESBSimpleSamples.ServiceClient.Generator.Scripts
{
    public abstract class ScriptBase
    {
        private StringWriter _output;
        private Dictionary<string, string> _parameters;
        protected WSDLMetadata _metadata;
        protected WSDLMethod _method;

        private Dictionary<string, string> Parameters
        {
            get
            {
                if (this._parameters == null)
                {
                    this._parameters = new Dictionary<string, string>();
                }
                return this._parameters;
            }
        }

        public WSDLMetadata Metadata
        {
            get { return _metadata; }
            set { _metadata = value; }
        }

        public WSDLMethod Method
        {
            get { return _method; }
            set { _method = value; }
        }

        protected string GetParameterValue(string parameterName)
        {
            string parameterValue = null;
            if (this.Parameters.ContainsKey(parameterName))
            {
                parameterValue = this.Parameters[parameterName];
            }
            return parameterValue;
        }

        protected void SetParameterValue(string parameterName, string parameterValue)
        {
            this.Parameters[parameterName] = parameterValue;
        }

        protected abstract void Process();
        public abstract string Name { get;}
        public abstract string Language { get;}

        public void Render()
        {
            this._output = null;
            this.Process();
        }

        public StringWriter Output
        {
            get
            {
                if (this._output == null)
                {
                    this._output = new StringWriter();
                }
                return this._output;
            }
        }
    }
}
